import Vue from 'vue'
import Router from 'vue-router'
import axios from 'axios'

Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/invest',//首页
      name: 'invest',
      component: (resolve) => {
        require(['@/components/invest'], resolve)
      },
      meta: { tabbar: 0,requiresAuth:false}
    },{
      path: '/pool',//首页
      name: 'pool',
      component: (resolve) => {
        require(['@/components/pool'], resolve)
      },
      meta: { tabbar: 0,requiresAuth:false}
    },{
      path: '/team',//代理
      name: 'team',
      component: (resolve) => {
        require(['@/components/team'], resolve)
      },
      meta: { tabbar: 1,requiresAuth:true}
    },{
      path: '/gainRecord',//代理收益记录
      name: 'gainRecord',
      component: (resolve) => {
        require(['@/components/gainRecord'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true}
    },{
      path: '/noticeList',//代理收益记录
      name: 'noticeList',
      component: (resolve) => {
        require(['@/components/myself/noticeList'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true}
    },{
      path: '/noticeDetail/:id',//代理收益记录
      name: 'noticeDetail',
      component: (resolve) => {
        require(['@/components/myself/noticeDetail'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true}
    },{
      path: '/inviteListPage',//邀请列表记录
      name: 'inviteListPage',
      component: (resolve) => {
        require(['@/components/inviteListPage'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true}
    },{
      path: '/investDetail/:id',//代理队友详情
      name: 'investDetail',
      component: (resolve) => {
        require(['@/components/investDetail'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true}
    },{
      path: '/purse',//钱包
      name: 'purse',
      component: (resolve) => {
        require(['@/components/purse'], resolve)
      },
      meta: { tabbar: 2,requiresAuth:true}
    },{
      path: '/my',//我的
      name: 'my',
      component: (resolve) => {
        require(['@/components/myself/my'], resolve)
      },
      meta: { tabbar: 3,requiresAuth:true}
    },{
      path: '/myChargeRecord',//我的 充提记录
      name: 'myChargeRecord',
      component: (resolve) => {
        require(['@/components/myself/myChargeRecord'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/donationRecord/:id?/:mark?',//我的 历史投注
      name: 'donationRecord',
      component: (resolve) => {
        require(['@/components/myself/donationRecord'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/contact',//我的 历史投注
      name: 'contact',
      component: (resolve) => {
        require(['@/components/myself/contact'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/myNoviceKnow',//我的 新手须知
      name: 'myNoviceKnow',
      component: (resolve) => {
        require(['@/components/myself/myNoviceKnow'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/mySafe',//我的 安全须知
      name: 'mySafe',
      component: (resolve) => {
        require(['@/components/myself/mySafe'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/forgetLoginPwd',//忘记登录密码
      name: 'forgetLoginPwd',
      component: (resolve) => {
        require(['@/components/forgetLoginPwd'], resolve)
      },
      meta: { exceptTabBar: true }
    },{
      path: '/withdrawPwd',//
      name: 'withdrawPwd',
      component: (resolve) => {
        require(['@/components/withdrawPwd'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/recharge/:id',//充币提币页面
      name: 'recharge',
      component: (resolve) => {
        require(['@/components/recharge'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/myEditLoginPwd',//支付密码
      name: 'myEditLoginPwd',
      component: (resolve) => {
        require(['@/components/myself/myEditLoginPwd'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/mySetPwd',//支付密码
      name: 'mySetPwd',
      component: (resolve) => {
        require(['@/components/myself/mySetPwd'], resolve)
      },
      meta: { exceptTabBar: true,requiresAuth:true }
    },{
      path: '/login',//登陆
      name: 'login',
      component: (resolve) => {
        require(['@/components/login'], resolve)
      },
      meta: { exceptTabBar: true }
    },{
      path: '/rules',//活动规则
      name: 'rules',
      component: (resolve) => {
        require(['@/components/rules'], resolve)
      },
      meta: { exceptTabBar: true}
    },{
      path: '/register:invite_code?',//注册
      name: 'register',
      component: (resolve) => {
        require(['@/components/register'], resolve)
      },
      meta: { exceptTabBar: true }
    },
    { path: '*', redirect: { name: 'invest' }}
  ]
})
router.beforeEach((to, from, next) => {
  if(to.path === '/login')  {
    next()
  }else {
    if(to.meta.requiresAuth && !localStorage.getItem('token')) {
      next({ path:'/login'})
    }else {
      next()
    }
    next()
  }
})
export default router
